import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * 检查用户是否没有修改过密码, 绑定过手机号 邮箱
 * 如果不满足 则 在第一次登录 提示用户去个人中心修改
 */
import React from 'react';
import { Modal, Button } from 'antd';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { getAsset } from '@cpaas-front-ui/cfg';
import intl from "../../../utils/intl";
import { getSession, setSession, getResponse } from "../../../utils/utils";
import { queryStaticText } from "../../../services/api";
import toastImg from "../../../assets/illustrate-toast.svg";
import styles from "./index.less?modules";

var DefaultCheckUserSafe = /*#__PURE__*/function (_React$Component) {
  _inherits(DefaultCheckUserSafe, _React$Component);

  var _super = _createSuper(DefaultCheckUserSafe);

  function DefaultCheckUserSafe(props) {
    var _this;

    _classCallCheck(this, DefaultCheckUserSafe);

    _this = _super.call(this, props);
    _this.state = {// needShowModal: false,
    };
    return _this;
  }

  _createClass(DefaultCheckUserSafe, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      var _this$props = this.props,
          currentUser = _this$props.currentUser,
          changePasswordFlag = _this$props.currentUser.changePasswordFlag;
      var infoCheckFlag = getSession('infoCheckFlag');

      if (!infoCheckFlag && currentUser || changePasswordFlag === 1) {
        var emailCheckFlag = currentUser.emailCheckFlag,
            phoneCheckFlag = currentUser.phoneCheckFlag,
            passwordResetFlag = currentUser.passwordResetFlag;

        if ((emailCheckFlag === 0 || phoneCheckFlag === 0 || passwordResetFlag === 0 || changePasswordFlag === 1) && !infoCheckFlag) {
          var nextState = {
            selfModalVisible: true,
            // needShowModal: true,
            passwordResetFlag: passwordResetFlag,
            emailCheckFlag: emailCheckFlag,
            phoneCheckFlag: phoneCheckFlag
          };
          queryStaticText('USER_PROMPT').then(function (res) {
            var staticRes = getResponse(res); // info 如果 没有模版， 那么不需要弹出提示

            if (staticRes && staticRes.text) {
              nextState.selfModalDangerouslySetInnerHTML = {
                __html: staticRes.text
              };
            }
          }).finally(function () {
            _this2.setState(nextState);

            setSession('infoCheckFlag', true);
          });
        }
      } else {// const { needShowModal } = this.state;
        // if(needShowModal) {
        //   this.setState({needShowModal: false});
        // }
      }
    }
  }, {
    key: "renderCheckModal",
    value: function renderCheckModal() {
      var _this3 = this;

      var _this$state = this.state,
          selfModalDangerouslySetInnerHTML = _this$state.selfModalDangerouslySetInnerHTML,
          selfModalVisible = _this$state.selfModalVisible,
          phoneCheckFlag = _this$state.phoneCheckFlag,
          emailCheckFlag = _this$state.emailCheckFlag,
          passwordResetFlag = _this$state.passwordResetFlag;
      var _this$props2 = this.props,
          gotoTab = _this$props2.gotoTab,
          _this$props2$currentU = _this$props2.currentUser,
          _this$props2$currentU2 = _this$props2$currentU.popoutReminderFlag,
          popoutReminderFlag = _this$props2$currentU2 === void 0 ? 1 : _this$props2$currentU2,
          changePasswordFlag = _this$props2$currentU.changePasswordFlag;
      return /*#__PURE__*/React.createElement(Modal, {
        visible: popoutReminderFlag && selfModalVisible,
        wrapClassName: styles['self-modal'],
        footer: null,
        width: 468,
        onCancel: function onCancel() {
          return _this3.setState({
            selfModalVisible: false
          });
        }
      }, /*#__PURE__*/React.createElement("div", {
        className: "self-modal-header"
      }, /*#__PURE__*/React.createElement("img", {
        src: getAsset('remind') || toastImg,
        alt: "toast-img",
        style: {
          width: '100%',
          height: 'auto'
        }
      })), /*#__PURE__*/React.createElement("div", {
        className: "self-modal-content"
      }, changePasswordFlag ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, intl.get('cpaas.common.basicLayout.greetMessage').d('尊敬的用户您好'), "\uFF0C"), /*#__PURE__*/React.createElement("p", null, intl.get('cpaas.common.basicLayout.passwordExpireMsg').d('您的密码即将到期，为保证消息的正常接收及您的账户安全，和后续的正常使用，请前往'), /*#__PURE__*/React.createElement("span", {
        className: "user-info"
      }, intl.get('cpaas.common.basicLayout.userInfo').d('个人中心')), intl.get('cpaas.common.basicLayout.safeMessage2').d('进行修改。'))) : selfModalDangerouslySetInnerHTML ?
      /*#__PURE__*/
      // eslint-disable-next-line react/no-danger
      React.createElement("div", {
        dangerouslySetInnerHTML: selfModalDangerouslySetInnerHTML
      }) : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, intl.get('cpaas.common.basicLayout.greetMessage').d('尊敬的用户您好'), "\uFF0C"), /*#__PURE__*/React.createElement("p", null, intl.get('cpaas.common.basicLayout.accountNoBind').d('系统检测到您的账号尚未绑定'), phoneCheckFlag === 0 && intl.get('cpaas.common.phone').d('手机'), emailCheckFlag === 0 && "".concat(phoneCheckFlag === 0 ? '、' : '').concat(intl.get('cpaas.common.email').d('邮箱')), passwordResetFlag === 0 && intl.get('cpaas.common.basicLayout.passwordReset').d('、系统密码为初始密码，'), intl.get('cpaas.common.basicLayout.safeMessage1').d('为保证消息的正常接收及您的账户安全，请前往'), /*#__PURE__*/React.createElement("span", {
        className: "user-info"
      }, intl.get('cpaas.common.basicLayout.userInfo').d('个人中心')), intl.get('cpaas.common.basicLayout.safeMessage2').d('进行修改。')))), /*#__PURE__*/React.createElement("div", {
        className: "self-modal-footer"
      }, /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        className: "go-info",
        onClick: function onClick() {
          gotoTab({
            pathname: '/ciam/user/info'
          });

          _this3.setState({
            selfModalVisible: false
          });
        }
      }, intl.get('cpaas.common.basicLayout.userInfo').d('个人中心'))));
    }
  }, {
    key: "render",
    value: function render() {
      // const { needShowModal } = this.state;
      // if (needShowModal) {
      return this.renderCheckModal(); // } else {
      // return null;
      // }
    }
  }]);

  return DefaultCheckUserSafe;
}(React.Component);

export default connect(function (_ref) {
  var _ref$user = _ref.user,
      user = _ref$user === void 0 ? {} : _ref$user;
  return {
    currentUser: user.currentUser
  };
}, function (dispatch) {
  return {
    gotoTab: function gotoTab(location, state) {
      return dispatch(routerRedux.push(location, state));
    }
  };
})(DefaultCheckUserSafe);